<template>
<div class="cacheManage">
  <search-block>
    <template slot="button">
      <el-button type="primary" @click="search">查询</el-button>
      <el-button type="primary" @click="refreshCache">刷新缓存</el-button>
    </template>
    <el-form inline :model="model" label-width="100px" @submit.native.prevent>
      <el-form-item label="表名:">
        <el-input v-model="model.tableName"></el-input>
      </el-form-item>
    </el-form>
  </search-block>
  <y-table
    border
    selection
    @selection-change="refreshSelection"
    :getDataWay="{
      data: tableData
    }"
    :columns="columns"
  ></y-table>
</div>
</template>

<script>
export default {
  name: "cacheManage",
  data(){
    return{
      model:{
        tableName: ''
      },
      tableData: [],
      selection: [],
      columns: [{
        label: "表名",
        prop: "tableName"
      },{
        label: "索引列",
        prop: "indexCaption"
      },{
        label: "存储类型",
        prop: "redisType"
      },{
        label: "分组字段",
        prop: "groupIndex"
      }]
    }
  },
  created() {
    this.search();
  },
  methods:{
    search(doSearch = true){
      this.$yAxios({
        url: this.$api.system.cacheList,
        data: doSearch ? this.model : {},
        loading: true
      }, info => {
        this.tableData = info;
      })
    },
    refreshSelection(selection){
      this.selection = selection
    },
    refreshCache(){
      if(this.selection.length){
        this.$yAxios({
          url: this.$api.system.refreshCache,
          data:{
            tableNames: this.selection.map(item => item.tableName)
          },
          loading: true
        }, info => {
          this.search(false);
          this.$message({
            type: 'success',
            message: '刷新成功'
          });
        })
      }
    }
  }
}
</script>

<style scoped>

</style>